import logging
import traceback
from pydiscovery2 import config


def on_initialize(date) -> list:
    logging.info(f'on_initialize(date = {date})')
    try:
        # todo
        # instrument_id_list = cta.on_initialize(date)
        return ['IF2006']
    except Exception as e:
        logging.error(traceback.format_exc())
        logging.error(f'on_initialize(date = {date}) exception({e})')
        raise Exception("strategy exception")


def on_bar(bar_field, bar_data) -> dict:
    logging.info(f'on_bar(bar_data = {bar_data})')
    # todo
    # portfolio = cta.on_bar()
    tpw = {'IF2006': 0.1}
    logging.info(f'on_bar(tpw = {tpw})')
    return tpw


def on_finalize():
    logging.info(f'on_finalize')
    # todo
